package org.example;

import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;





public class operation {

    static Scanner scanner = new Scanner(System.in);
    // 查询所有学生信息
    public static void findStu(ArrayList<Student> students){
        System.out.println("大小为"+students.size());
        for (Student ii : students) {
            System.out.println(ii.getName() + ii.getAge() + ii.getStudentId() + ii.getStudentClass());
        }
    }

    // 添加学生信息
    public static void addStudent(ArrayList<Student> students) {
        for(int a=0;a<1000;a++){
            System.out.println("输入学生的姓名：");
            String name = scanner.next();
            System.out.println("输入学生的年龄：");
            Integer age = scanner.nextInt();
            System.out.println("输入学生的学号：");
            Integer no = scanner.nextInt();
            System.out.println("输入学生的班级：");
            String Class = scanner.next();
            students.add(new Student(name, age, no, Class));
            System.out.println("是否继续添加学生：n/y");
            String banduan = scanner.next();
            if(Objects.equals(banduan, "n")){
                break;
            }
        }
    }

    //  查询单个学生
    public static void searchStudent(ArrayList<Student> students){
        System.out.println("请输入要查询学生的学号：");
        int id = scanner.nextInt();
        int i=0;
        for (Student s:students){
            if(id ==s.getStudentId()){
                System.out.println(students.get(i).getName());
            }
            else if( i++ ==students.size()){
                System.out.println("暂无此学生");
            }
        }
    }


    //  更新学生信息
    public static void updateStu(ArrayList<Student> students){
        System.out.println("请输入要修改学生的学号：");
        int id = scanner.nextInt();
        int i=0;
        for (Student s:students){
            if(id ==s.getStudentId()){
                System.out.println("输入学生的姓名：");
                String name = scanner.next();
                System.out.println("输入学生的年龄：");
                Integer age = scanner.nextInt();
                System.out.println("输入学生的学号：");
                Integer no = scanner.nextInt();
                System.out.println("输入学生的班级：");
                String Class = scanner.next();
                Student student = new Student(name,age,no,Class);
                students.set(i,student);
                System.out.println("学生信息修改成功");
                System.out.println("是否继续修改学生信息：n/y");
                String banduan = scanner.next();
                if(Objects.equals(banduan, "n")){
                    break;
                }
            }
            else if (i == students.size()) {
                System.out.println("暂无此学生");
            }
            i++;
        }


    }

    //   删除学生信息
    public static void removeStu(ArrayList<Student> students) {
        System.out.println("请输入要删除学生的学号：");
        int id = scanner.nextInt();
        int i = 0;
        for (Student s : students) {
            if (id == s.getStudentId()) {
                students.remove(i);
                System.out.println("学生信息删除成功");
                break;
            }
            else if (i == students.size()) {
            System.out.println("暂无此学生");
                 }
        i++;
        }
    }
}
